$(function () {
    $("#member_datagrid").datagrid({
        url:'/sale/memberConsumeInfo',
        fit:true,
        fitColumns:true,
        striped:true,

        columns:[
            [
                {field:'memberName',title:'会员名称',align:'center',width:100},
                {field:'saleCount',title:'消费次数',align:'center',width:100},
                {field:'totalAmount',title:'消费总金额',align:'center',width:100},
                {field:'totalMoney',title:'充值总金额',align:'center',width:100},
            ]
        ],
        pagination:true,
        rownumbers:true,
        singleSelect:true,
        onLoadSuccess:function (data) {
            var xData = new Array();
            var yData = new Array();
            var datas = data.rows;
            for(var i in datas){
                xData[i]=datas[i].memberName;
                yData[i]=datas[i].totalAmount;
            }

            // 基于准备好的dom，初始化echarts图表
            var myChart = echarts.init(document.getElementById('main'));
            var option = {
                tooltip: {
                    show: true
                },
                toolbox: {
                    show : true,
                    feature : {
                        mark : {show: true},
                        dataView : {show: true, readOnly: false},
                        magicType : {show: true, type: ['line', 'bar']},
                        restore : {show: true},
                        saveAsImage : {show: true}
                    }
                },
                legend: {
                    data: ['消费金额'],
                    x:'left'
                },
                xAxis: [
                    {
                        type: 'category',
                        data: xData,
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: [
                    {
                        "name": "消费金额",
                        "type": "bar",
                        "data": yData,
                        markPoint : {
                            data : [
                                {type : 'max', name: '最大值'},
                                {type : 'min', name: '最小值'}
                            ]
                        },
                        markLine : {
                            data : [
                                {type : 'average', name: '平均值'}
                            ]
                        }
                    }
                ]
            };

            // 为echarts对象加载数据
            myChart.setOption(option);
        }
    });
    $.post('/sale/selectData',function (data) {
        if(data){
            console.log(data.rows[0].totalAmount);
            $.each(data.rows,function (index,options) {
                $("#consumeCount").text(options.saleCount);
                $("#consumeAmount").text("￥"+options.totalAmount);
                $("#chargeAmount").text("￥"+options.totalMoney);
                $("#nameList").text("￥"+options.memberName);
            })


        }
    });
})
